<template>
    <div class="login-view">
        <section class="container">
            <div class="logo">
                <img src="../../assets/images/login-illustration.png">
            </div>
            <div class="form-view">
                <div class="form">
                    <img src="../../assets/logo.png">
                    <p>欢迎登云智选管理平台</p>
                    <el-form autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm">
                        <el-form-item prop="account">
                            <el-input v-model="loginForm.account" name="account" autoComplete="on" maxlength="11" clearable @keyup.enter.native="handleLoginBySms" placeholder="请输入账号">
                                <i slot="prefix" class="el-input__icon el-icon-mobile-phone"></i>
                            </el-input>
                        </el-form-item>
                        <el-form-item prop="password" class="sms-code">
                            <el-input v-model="loginForm.password" show-password name="password" autoComplete="on" maxlength="16" clearable @keyup.enter.native="handleLoginBySms"  placeholder="请输入密码">
                                <i slot="prefix" class="el-input__icon el-icon-lock"></i>
                            </el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" :loading="loading" @click.native.prevent="handleLoginBySms">登 录</el-button>
                        </el-form-item>
                    </el-form>
                </div>
            </div>
        </section>
    </div>
</template>

<script>
export default {
    name:"login",
    data(){
        return {
            loginForm: {
                account: "",
                password: ""
            },
            loginRules: {
                account: [{required: true, trigger: "blur", message: '请输入账户名'}],
                password: [{required: true, trigger: "blur", message: "请输入密码"}]
            },
            loading: false
        }
    },
    methods:{
        handleLoginBySms() {
            let self = this;
            self.$refs["loginForm"].validate(valid => {
                if (valid) {
                    self.loading = true;
                    self.$store.dispatch("StoreLoginByPwd", self.loginForm).then((res) => {
                       if(res.code == 0){
						   self.loading = false;
						   this.$router.replace("/");
					   }else{
						   this.$message.error(res.status)
						   self.loading = false;
					   }
                    }).catch(error => {
                        self.loading = false;
                    });
                }
            });
        }
    }
};
</script>

<style scoped lang="scss">

.login-view {
    width: 100%;
    height: 100vh;
    background-color: rgba(84,92,100, 1);
    position: relative;

    & > .container {
        width: 800px;
        height: 420px;
        background-color: #fff;
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        margin: auto;
        box-shadow: 0 0 5px #fff;

        & > div {
            display: inline-block;
            vertical-align: top;

            &.logo {
                width: 388px;
                height: 100%;
                // background-color: rgba(248, 249, 251, 1);
                position: relative;

                & > img {
                    width: 358px;
                    height: 358px;
                    display: block;
                    position: absolute;
                    top: 0;
                    left: 0;
                    right: 0;
                    bottom: 0;
                    margin: auto;
                }
            }

            &.form-view {
                width: calc(100% - 388px);
                height: 100%;
                position: relative;
                padding: 48px;
                box-sizing: border-box;

                & > .switch {
                    width: 60px;
                    height: 60px;
                    position: absolute;
                    top: 0;
                    right: 0;
                    background-image: url("../../assets/images/login-icon.png");
                    background-size: 150px 150px;
                    background-repeat: no-repeat;
                    cursor: pointer;

                    &.wx {
                        background-position: -88px 0;
                    }

                    &.pc {
                        background-position: -88px -88px;
                    }
                }

                & > .code {

                    & > h2 {
                        line-height: 33px;
                        font-size: 24px;
                        color: #303133;
                        font-weight: normal;
                        text-align: center;
                        letter-spacing: 1.5px;
                    }

                    & > .qr {
                        width: 210px;
                        height: 210px;
                        border: solid 1px #e1e1e1;
                        margin: 30px auto;
                        padding: 3px;
                        box-sizing: border-box;
                    }

                    & > p {
                        color: #909399;
                        font-size: 14px;
                        text-align: center;
                    }
                }

                & > .form {

                    & > img {
                        width: 56px;
                        height: 56px;
                        display: block;
                        margin: 0 auto;
                    }

                    & > p {
                        line-height: 20px;
                        font-size: 14px;
                        color: #909399;
                        font-weight: normal;
                        text-align: center;
                        margin: 10px auto 30px;
                        letter-spacing: 1.5px;
                    }

                    & > .el-form {
                        & .el-button {
                            width: 100%;
                        }
                    }

                    & .sms-code {
                        position: relative;

                        & .el-button {
                            width: 100px;
                            position: absolute;
                            top: 0;
                            right:0;
                        }
                    }

                    & .check {
                        & span {
                            font-size: 12px;
                            color: #909399;
                            margin-left: 8px;

                            &:nth-of-type(2) {
                                @include font_color($r, $g, $b, 1);
                                cursor: pointer;
                                margin: 0;
                            }
                        }
                    }
                }
            }
        }
    }

    & .page-model {
        width: 100%;
        height: 100vh;
        background-color: rgba(0, 0, 0, 0.5);
        position: fixed;
        top: 0;
        left: 0;
        z-index: 9999999;

        &>.page-model-content {
            width: 1000px;
            height: 700px;
            background-color: #ffffff;
            border-radius: 5px;
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            margin: auto;
            padding: 30px;
            box-sizing: border-box;

            &>h2 {
                font-size: 25px;
                color: #303030;
                text-align: center;
                margin: 10px 0;
            }

            &>h4 {
                font-size: 16px;
                color: #333;
                text-align: left;
                font-weight: 300;
                margin: 10px 0;
            }

            &>.page-model-content_content {
                width: 100%;
                height: 450px;
                border: solid 1px #ebebeb;
                border-radius: 3px;
                margin-bottom: 20px;
                overflow-x: hidden;
                overflow-y: auto;
                padding: 15px 20px;
                box-sizing: border-box;

                &>h2 {
                    font-size: 16px;
                    color: #000;
                    font-weight: bold;
                    margin: 10px 0;
                }

                &>p {
                    font-size: 13px;
                    color: #555;
                    text-indent: 2em;
                    letter-spacing: 1px;
                    line-height: 30px;
                    margin: 10px 0;

                    &>b {
                        color: #000;
                    }
                }
            }

            &>.page-model-content_btn {
                display: block;
                margin: 0 auto;
            }
        }
    }
}
</style>
